package com.qingdai.controller;

import com.qingdai.emuns.AddressDTO;
import com.qingdai.emuns.CommodityDTO;
import com.qingdai.emuns.OrderDTO;
import com.qingdai.entities.CommonResult;
import com.qingdai.service.AddressService;
import com.qingdai.service.CommodityService;
import com.qingdai.service.OrderService;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class TestController {

    @Resource
    private AddressService addressService;
    @Resource
    private CommodityService commodityService;
    @Resource
    private OrderService orderService;

    @GetMapping("/test")
    public Authentication getLoginUser(Authentication authentication) {
        return authentication;
    }

    @PreAuthorize("hasRole('超级管理员')")  //预授权 在调用方法前检验
    @GetMapping("/test2")
    public String test() {
        return "aaaaaaaaaaaaaaaaaaaaa";
    }
    @GetMapping("/test3")
    public CommonResult aa() {
        List<AddressDTO> addressDTO = addressService.getAddressDTOByUserId(1);
        List<CommodityDTO> commodityDTO = commodityService.getCommodityDTOByShopId(1);
        List<OrderDTO> orderDTO = orderService.getOrderDTOById(1);
        return new CommonResult<>(200,"",orderDTO);
    }
}
